package com.yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.ibatis.session.SqlSession;

import com.yunhe.bean.CommodityEvaluation;
import com.yunhe.inter.CommodityEvaluationInter;
import com.yunhe.util.SqlSessionFactoryUtil;

/**
 * 用于评论信息的展示
 */
@WebServlet("/ShowEvaluationInfoServlet")
public class ShowEvaluationInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public ShowEvaluationInfoServlet() {
        super();
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setHeader("Charset", "UTF-8");
		response.setCharacterEncoding("UTF-8");
		//获取ajax传递过来的商品的ID
		String commodity=request.getParameter("commodityID");
		System.out.println(commodity);
		Integer commodityID=Integer.parseInt(request.getParameter("commodityID").toString());
		//获取数据库连接
		SqlSession sqlSession =SqlSessionFactoryUtil.openSqlSession();
    	CommodityEvaluationInter mapper = sqlSession.getMapper(CommodityEvaluationInter.class);
    	ArrayList<CommodityEvaluation> cdeList =  mapper.showEvaluationInfo(1, commodityID);
    	//创建并获得JSON对象
    	JSONArray arrayList = JSONArray.fromObject(cdeList);
    	
    	//创建out对象
    	PrintWriter out = response.getWriter();
    	//前台ajax通过此方法进行数据获取
    	out.write(arrayList.toString());
    	
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
